package com.zprmb.udzt.fragment;

import java.util.ArrayList;

import org.json.JSONObject;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.ProductZT;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.VolleryUtil;

public class LingcunBillfragment extends Fragment implements OnRefreshListener2<ListView>{
	private PullToRefreshListView lv_product_fragment;
	private ListView lv;
	private ListView actualListView;
	private ArrayList<ProductZT> list = new ArrayList<ProductZT>();
	private ArrayList<ProductZT> list2 = new ArrayList<ProductZT>();

	private int page=1;
	private String type,token;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		type=getArguments().getString("type");
		token=getArguments().getString("token");
	}
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view=inflater.inflate(R.layout.lingcun_bill, null);
		lv_product_fragment = (PullToRefreshListView) view.findViewById(R.id.lv);
		actualListView = lv_product_fragment.getRefreshableView();
		registerForContextMenu(actualListView);
		lv_product_fragment.setOnRefreshListener(this);
		lv_product_fragment.setMode(Mode.BOTH);
		initData();
		return view;
	}
	private void initData() {
		// TODO Auto-generated method stub
		VolleryUtil volleryUtil=new VolleryUtil() {
			
			@Override
			public void onUpDate(JSONObject jsonObject) {
				// TODO Auto-generated method stub
				Log.e("bill", jsonObject.toString());
			}
			
			@Override
			public void onError() {
				// TODO Auto-generated method stub
				
			}
		};
		volleryUtil.setHeaders("token", token);
		volleryUtil.setRequestMethod(0);
		if(type.equals("in")){
			volleryUtil.execute(getActivity(), Constant.URL+"/api/v2/current/user/inRecordt?pageNo="+page+"&pageSize=10", "");
			
		}else{
			volleryUtil.execute(getActivity(), Constant.URL+"/api/v2/current/user/outRecordt?pageNo="+page+"&pageSize=10", "");
			
		}
	}
	public static LingcunBillfragment newInstance(String token, String string) {
		LingcunBillfragment uf = new LingcunBillfragment();
		Bundle bundle=new Bundle();
		bundle.putString("type", string);
		bundle.putString("token", token);
		uf.setArguments(bundle);
		
		return uf;
	}
	@Override
	public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
		// TODO Auto-generated method stub
		
	}
	

}
